
<template>
  <el-container>
    <el-aside width="390px" style="background-color: #fafdff" class="cebian" v-if="show">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
        <el-form-item label="选择患者" prop="">
          <el-input
            v-model="queryParams.patientId"
            placeholder="患者姓名"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-form>
      <div v-for="(item, key) of mzyslist[0]">
        <div v-if="key=='list1'&&item.length>0" style="background-color: #00afff">待诊患者</div>
        <div v-if="key=='list2'&&item.length>0" style="background-color: #00afff">就诊患者</div>
        <div v-if="key=='list3'&&item.length>0" style="background-color: #00afff">诊毕患者</div>
        <div style="height: 50px"></div>
      <el-table v-loading="loading" :data="item" @selection-change="handleSelectionChange" v-if="item.length>0"  @row-click="showDialog($event)">
        <el-table-column label="病例号" align="center" prop="medicalRecordNo" />
        <el-table-column label="名字" align="center" prop="name" />
        <el-table-column label="年龄" align="center" prop="patient_age_str" />
      </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getPatientList"
          v-if="item.length>0"
        />
        <div style="height: 50px"></div>
      </div>
    </el-aside>
    <el-dialog
      title="就诊"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <span>确定开始诊断患者</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
    <el-main>
  <div class="app-container">
    <el-row>
        <el-col>
             <span style="margin-right: 20px"><el-button type="primary" icon="el-icon-arrow-left" circle @click="suojin" v-if="show"></el-button></span>
            <span style="margin-right: 20px"><el-button type="primary" icon="el-icon-arrow-right" circle @click="suojin" v-if="!show"></el-button></span>
            <span>当前病人：</span>
          <span>

            <el-input placeholder="姓名：" style="width:100px;" class="input1" >

            </el-input>
          <el-input placeholder="就诊号：" style="width: 100px">

            </el-input>
            <el-input placeholder="性别：" style="width: 100px">

            </el-input>
            <el-input placeholder="年龄：" style="width: 100px">

            </el-input>
          </span>
        </el-col>
    </el-row>
    <el-row>
      <el-col>
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
          <el-tab-pane label="病历首页" name="blsy"/>
          <el-tab-pane label="检查申请" name="jcsq"/>
          <el-tab-pane label="检验申请" name="jysq"/>
          <el-tab-pane label="门诊确诊" name="mzqz"/>
          <el-tab-pane label="成药处方" name="cycf"/>
          <el-tab-pane label="草药处方" name="caoycf"/>
          <el-tab-pane label="处置申请" name="czsq"/>
          <el-tab-pane label="患者账单" name="hzzd"/>
        </el-tabs>
      </el-col>
    </el-row>
    <el-container style="height: 500px; border: 1px solid #eee">
      <el-aside width="700px" style="background-color: rgb(247,250,255);height: 500px;">
    <el-row>
      <el-col>
        <el-button type="primary" plain>病例内容</el-button>
        <el-button
          size="mini"
          type="text"
          icon="el-icon-upload2"
        >暂存</el-button>
        <el-button
          size="mini"
          type="text"
          icon="el-icon-download"
        >取出暂存病历</el-button>
        <el-button
        icon="el-icon-caret-right"
        >
        快速操作
        </el-button>
      </el-col>
    </el-row>
  <el-row>
    <el-col style="float:left">
      <div>
        <span style="width:50px;height: 100px;line-height: 50px">主诉</span><el-input
        type="textarea"
        :autosize="{ minRows: 2, maxRows: 4}"
        style="width: 500px"
        placeholder="请输入内容"
        v-model="textarea2">
      </el-input>
      </div>
      <div style="margin: 20px 0;"></div>
      <div>
        <span style="width:50px;">现病史</span>
      <el-input
        type="textarea"
        style="width: 500px"
        autosize
        placeholder="现病史"
        v-model="textarea1">
      </el-input>
      </div>
      <div style="margin: 20px 0;"></div>
      <div>
        <span style="width:50px;">现病治疗情况</span>
        <el-input
          type="textarea"
          style="width: 500px"
          autosize
          placeholder="现病治疗情况"
          v-model="textarea3">
        </el-input>
      </div>
      <div style="margin: 20px 0;"></div>
      <div>
        <span style="width:50px;">既往史</span>
        <el-input
          type="textarea"
          style="width: 500px"
          autosize
          placeholder="既往史"
          v-model="textarea4">
        </el-input>
      </div>
      <div style="margin: 20px 0;"></div>
      <div>
        <span style="width:50px;">过敏史</span>
        <el-input
          type="textarea"
          style="width: 500px"
          autosize
          placeholder="过敏史"
          v-model="textarea5">
        </el-input>
      </div>
      <div style="margin: 20px 0;"></div>
      <div>
        <span style="width:50px;">体格检查</span>
        <el-input
          type="textarea"
          style="width: 500px"
          autosize
          placeholder="体格检查"
          v-model="textarea6">
        </el-input>
      </div>
      <div style="margin: 20px 0;"></div>
        <div class="block">
          <span style="width:50px;">发病时间</span>
          <el-date-picker
            v-model="textarea7"
            align="right"
            type="date"
            placeholder="选择日期"
            :picker-options="pickerOptions">
          </el-date-picker>
        </div>
      <el-tag>评估诊断:</el-tag>
      <el-card>
        <el-button type="text" style="float:right" @click="showDiseList"
        >添加诊断</el-button
        >
        <el-table :data="diseList">
          <el-table-column label="ICD编码" prop="icd"></el-table-column>
          <el-table-column label="名称" prop="name"></el-table-column>
          <el-table-column label="编码" prop="code"></el-table-column>
          <el-table-column width="80">
            <template slot-scope="scope">
              <el-button type="text" @click="deleteDis(scope.row)"
              >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-card>
<!--      <DiseList-->
<!--        ref="DiseList"-->
<!--        @diseListCallback="updateDiseList"-->
<!--        :selectedDiseList="diseList"-->
<!--      ></DiseList>-->
      <el-button  style="margin-top:10px;" type="primary" size="mini" @click="saveCaseModel"
      >提交初诊</el-button>

    </el-col>
  </el-row>
      </el-aside>
      <el-container v-if="!show">
        <el-header style="text-align: right; font-size: 12px">
          <el-tabs v-model="activeName1" @tab-click="handleClick">
            <el-tab-pane label="病历模板" name="blmb"></el-tab-pane>
            <el-tab-pane label="常用诊断" name="cyzd"></el-tab-pane>
            <el-tab-pane label="历史病历" name="lsbl"></el-tab-pane>
          </el-tabs>
        </el-header>

        <el-main>
          <el-table :data="dms_case_model_catalogList">
            <el-table-column prop="name" label="病历名" width="140"/>
            <el-table-column prop="bname" label="主要诊断" width="120"/>
          </el-table>
        </el-main>
      </el-container>
    </el-container>
  </div>

    </el-main>
  </el-container>
</template>

<script>
import { listRegistration, getRegistration, delRegistration, addRegistration, updateRegistration, exportRegistration } from "@/api/dms/registration";
import { listPatient, getPatient, delPatient, addPatient, updatePatient, exportPatient,listHuanZhe} from "@/api/pms/patient";
// 导入疾病列表组件
import DiseList from "@/components/Dms/Dise/";
import {
  listDms_case_model,
  getDms_case_model,
  delDms_case_model,
  addDms_case_model,
  updateDms_case_model,
  exportDms_case_model
} from "@/api/dms/dms_case_model";
import { listDms_case_model_catalog, getDms_case_model_catalog, delDms_case_model_catalog, addDms_case_model_catalog, updateDms_case_model_catalog, exportDms_case_model_catalog } from "@/api/dms/dms_case_model_catalog";
export default {
  name: "Registration",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 注册子组件
      components: { DiseList },
      // 总条数
      total: 0,
      // 就诊信息表格数据
      registrationList: [],
      // 弹出层标题
      title: "",
      dialogVisible: false,
      // 是否显示弹出层
      open: false,
      //默认选中标签标签页
      activeName: 'blsy',
      activeName1: 'blmb',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
      },
      textarea1: '',
      textarea2: '',
      textarea3: '',
      textarea4: '',
      textarea5: '',
      textarea6: '',
      textarea7: '',
      display: true,
      show:true,
      // 疾病列表
      diseList: [],
      // 表单参数
      form: {},
      mzys: [],
      mzyslist:[],
      //查询病历模板列表
      dms_case_modelList:[],
      // 病例模版目录表格数据
      dms_case_model_catalogList: [],
      su:[1,2,3],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
      value1: '',
      value2: '',
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getPatientList();
    this.getblmbmlList();
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});

  },
    showDialog(value){
      this.dialogVisible=true;
    },
    /** 查询病例模版目录列表 */
    getblmbmlList() {
      this.loading = true;
      listDms_case_model_catalog(this.queryParams).then(response => {
        this.dms_case_model_catalogList=response.data;
        this.loading = false;
      });
    },
    // 显示疾病列表组件
    showDiseList() {
      this.$refs.DiseList.addDise();
    },
    /** 查询病例模版列表 */
    getblmbList() {
      this.loading = true;
      listDms_case_model(this.queryParams).then(response => {
        this.dms_case_modelList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    saveCaseModel() {
      if (this.diseList) {
        this.form.priliminaryDiseIdList = this.diseList.map(item => item.id).join(",");
        this.form.priliminaryDiseStrList = this.diseList.map(item => item.name).join(",");
      }
      this.submitForm();
    },
    // 添加疾病
    updateDiseList(data) {
      this.diseList.push(data);
      this.$message({
        message: "添加成功",
        type: "success"
      });
    },
    suojin(){
      this.show = !this.show;
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    getPatientList(){
      listHuanZhe(this.queryParams).then(response=>{
        this.mzyslist=response.rows;
        console.log(this.mzyslist)
          // this.mzys.splice(0,1,this.mzyslist)
          // this.total=response.total;
        })
    },
    /** 查询就诊信息列表 */
    getList() {
      this.loading = true;
      listRegistration(this.queryParams).then(response => {
        this.registrationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        patientId: null,
        createTime: null,
        endAttendance: null,
        status: 0,
        skdId: null,
        needBook: null,
        bindStatus: 0,
        deptId: null,
        attendanceDate: null,
        patientAgeStr: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加就诊信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRegistration(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改就诊信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRegistration(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addRegistration(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除就诊信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRegistration(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有就诊信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportRegistration(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
<style>
  .blmb{
    display: none;
  }
  .input1::-webkit-input-placeholder {

    color: #da1502;

  }

  *{
    padding:0; margin:0;
    font-size: 13px;
  }
  .el-row {
    margin-bottom: 20px;

  }
  .el-col {
    border-radius: 4px;
  }


</style>
